package cn.otrue.patienthealthmanager.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import cn.otrue.patienthealthmanager.R;
import cn.otrue.patienthealthmanager.view.MyTextView;

public class TextAdapter extends BaseAdapter {
	List<Map<String, String>> otherData;
	private Context ctx;
	private int textSize = -1;

	public TextAdapter(Context ctx, List<Map<String, String>> otherData) {
		super();
		this.otherData = otherData;
		this.ctx = ctx;

		textSize = 16;

	}

	@Override
	public int getCount() {
		return otherData.size();
	}

	@Override
	public Object getItem(int position) {
		return otherData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		MyTextView inflate = (MyTextView) LayoutInflater.from(ctx).inflate(
				R.layout.item_body_state, null);

		Map<String, String> map = otherData.get(position);
		inflate.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
		inflate.setText(map.get("diseasename"));
		if (map.containsKey("state") && map.get("state").equals("1")) {
			inflate.setSelected(true);
		} else {
			inflate.setSelected(false);
		}

		return inflate;
	}
}
